package com.example.nacoscloudconsumer;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@Slf4j
public class NacosCloudConsumerApplication {

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    public static void main(String[] args) {
        SpringApplication.run(NacosCloudConsumerApplication.class, args);
    }

    @RestController
    public class TestController {

//        private final RestTemplate restTemplate;
//
//        @Autowired
//        public TestController(RestTemplate restTemplate) {
//            this.restTemplate = restTemplate;
//        }
//
//        @RequestMapping(value = "sentinel", method = RequestMethod.GET)
//        @SentinelResource("sentinel")
//        public String sentinel() {
//            return "hello Sentinel";
//        }
//
//        @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
//        public String echo(@PathVariable String str) {
//            return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
//        }

//        @RequestMapping(value = "/search/art/getPage", method = RequestMethod.GET)
//        public Object artPage(String content, String title) {
//            Object forObject = restTemplate.getForObject("http://elasticsearch/search/art/getPage?title=" + title + "&content=" + content, Object.class);
//            log.info("artObject:{}", forObject);
//            return forObject;
//        }
//
//        @RequestMapping(value = "/search/video/getPage", method = RequestMethod.GET)
//        public Object videoPage(String content, String title) {
//            Object object = restTemplate.getForObject("http://elasticsearch/search/video/getPage?title=" + title + "&content=" + content + content, Object.class);
//            log.info("videoObject:{}", object);
//            return object;
//        }

      /*  @RequestMapping(value = "/zookeeper/createNode", method = RequestMethod.GET)
        public Object createNode(String nodeName, String nodeValue) {
            String object = restTemplate.getForObject("http://zookeeper/createNode?nodeName=" + nodeName + "&nodeValue=" + nodeValue, String.class);
            log.info("videoObject:{}", object);
            return object;
        }

        @RequestMapping(value = "/zookeeper/deleteNode", method = RequestMethod.GET)
        public Object deleteNode(String nodeName) {
            String str = restTemplate.getForObject("http://zookeeper/deleteNode?nodeName=" + nodeName, String.class);
            log.info("videoObject:{}", str);
            return str;
        }

        @RequestMapping(value = "/zookeeper/getNodes")
        public Object getNodes(){
            try {
                Object nodes = restTemplate.getForObject("http://zookeeper/getNodes", Object.class);
                return nodes;
            } catch (Exception e) {
                log.error("getNodes func fail message:{}", e.getMessage());
                return null;
            }
        }

        @RequestMapping(value = "/zookeeper/getData")
        public Object getData(){
            try {
                Object data = restTemplate.getForObject("http://zookeeper/getData", Object.class);
                return data;
            } catch (Exception e) {
                log.error("getData func fail message:{}", e.getMessage());
                return null;
            }
        }*/
    }

}
